Enter the directory of the maca folder on your drive and the name of the tissue you want to analyze.
tissue_of_interest = "Tongue"
library(here)
here() starts at /Users/olgabot/code/tabula-muris
source(here("00_data_ingest", "02_tissue_analysis_rmd", "boilerplate.R"))
package ‘dplyr’ was built under R version 3.4.2
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
tiss = load_tissue_droplet(tissue_of_interest)
Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
|----|----|----|----|----|----|----|----|----|----|
**************************************************|
[1] "Scaling data matrix"
|
| | 0%
|
|===== | 4%
|
|========== | 8%
|
|=============== | 12%
|
|==================== | 17%
|
|========================== | 21%
|
|=============================== | 25%
|
|==================================== | 29%
|
|========================================= | 33%
|
|============================================== | 38%
|
|=================================================== | 42%
|
|======================================================== | 46%
|
|============================================================== | 50%
|
|=================================================================== | 54%
|
|======================================================================== | 58%
|
|============================================================================= | 62%
|
|================================================================================== | 67%
|
|======================================================================================= | 71%
|
|============================================================================================ | 75%
|
|================================================================================================= | 79%
|
|====================================================================================================== | 83%
|
|============================================================================================================ | 88%
|
|================================================================================================================= | 92%
|
|====================================================================================================================== | 96%
|
|===========================================================================================================================| 100%
Calculating gene means
0% 10 20 30 40 50 60 70 80 90 100%
|----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating gene variance to mean ratios
0% 10 20 30 40 50 60 70 80 90 100%
|----|----|----|----|----|----|----|----|----|----|
**************************************************|
Later on (in FindClusters and TSNE) you will pick a number of principal components to use. This has the effect of keeping the major directions of variation in the data and, ideally, supressing noise. There is no correct answer to the number to use, but a decent rule of thumb is to go until the plot plateaus.
PCElbowPlot(object = tiss)
Choose the number of principal components to use.
# Set number of principal components.
n.pcs = 14
The clustering is performed based on a nearest neighbors graph. Cells that have similar expression will be joined together. The Louvain algorithm looks for groups of cells with high modularity–more connections within the group than between groups. The resolution parameter determines the scale…higher resolution will give more clusters, lower resolution will give fewer.
For the top-level clustering, aim to under-cluster instead of over-cluster. It will be easy to subset groups and further analyze them below.
# Set resolution
res.used <- 0.4
tiss <- FindClusters(object = tiss, reduction.type = "pca", dims.use = 1:n.pcs,
resolution = res.used, print.output = 0, save.SNN = TRUE, force.recalc = TRUE)
To visualize
# If cells are too spread out, you can raise the perplexity. If you have few cells, try a lower perplexity (but never less than 10).
tiss <- RunTSNE(object = tiss, dims.use = 1:n.pcs, seed.use = 20, perplexity=35, dim.embed = 2)
TSNEPlot(object = tiss, do.label = T, pt.size = 1.2, label.size = 4)
Check expression of genes of interset.
Dotplots let you see the intensity of exppression and the fraction of cells expressing for each of your genes of interest.